#include "ProCon1.hpp"

void *Pro(void *asg)
{
    pthread_detach(pthread_self());
    PC<int> *qc = (PC<int> *)asg;
    while (true)
    {
        sleep(1);
        int data = rand() % 100 + 1;
        qc->Push(data);
        std::cout << "生产者生产了:" << data << std::endl;
    }
}


void *Con(void *asg)
{
    pthread_detach(pthread_self());
    PC<int> *qc = (PC<int> *)asg;
    while (true)
    {
        sleep(2);
        int data = 0;
        qc->Pop(data);
        std::cout << "消费者消费了:" << data << std::endl;
    }
}

int main()
{
    pthread_t producer,consumer;
    // 定义随机种子
    srand((unsigned long)time(nullptr));
    PC<int> *qc = new PC<int>();
    pthread_create(&producer, nullptr, Pro, qc);
    pthread_create(&consumer, nullptr, Con, qc);
    
    while (true)
        ;
    
    return 0;
}